<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h2>插件</h2>
      <input type="text" v-focus />
      <my-header></my-header>
      <p>{{msg}}</p>
    </div>

    <script src="./lib/vue3.js"></script>
    <script>
      const app = Vue.createApp({
        inject: ["msg"],
        data() {
          return {};
        },
        mounted() {
          console.log(this.$abc);
          this.$fn();
        },
      });

      // use方法用于添加插件
      // 插件用于添加全局功能
      app.use({
        install(app, options) {
          // 配置此应用
          // 可以添加全局组件
          app.component("MyHeader", { template: "<div>头部组件</div>" });

          // 添加全局的自定义指令
          app.directive("focus", {
            mounted(el) {
              el.focus();
            },
          });

          // 添加全局的依赖
          app.provide("msg", "hello");

          // 添加全局的属性和方法
          app.config.globalProperties.$abc = 123;
          app.config.globalProperties.$fn = () => {
            console.log("fn");
          };
        },
      });

      app.mount("#app");
    </script>
  </body>
</html>
